// pages/my-team/my-team.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teamList: [],
    isLoad: true,
    pageNum: 1,
    teamTotal: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({userInfo: app.globalData.userInfo})
    this.getTeamList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.isLoad){
      return false;
    }
    this.getTeamList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  jumpPage(param){
    wx.navigateTo({ url: param.currentTarget.dataset.path})
  },
  getTeamList(){
      var that = this
      wx.request({
        url: app.globalData.apiPath + 'wechat/getMyTeam',
        method: 'POST',
        data: {popenid: that.data.userInfo.openid},
        success (res) {
            console.log(res)
            var list = res.data.data.records;
            var isLoad = that.data.isLoad,pageNum = that.data.pageNum,teamTotal = res.data.data.total
            if(res.data.data.pages >  that.data.pageNum){
                pageNum = pageNum+1
            }else{
              isLoad = false
            }
            var allList = that.data.teamList.concat(list);
            that.setData({teamList: allList,isLoad:isLoad,pageNum:pageNum,teamTotal:teamTotal})
        }
      })
  },

})